+import Adw from 'gi://Adw';
import GObject from 'gi://GObject';
import {ExtensionBase, GettextWrapper} from './sharedInternals.js';
}
/**
- * Fill the preferences window with preferences.
+ * Get the single widget that implements
+ * the extension's preferences.
*
- * @param {Adw.PreferencesWindow} _window - the preferences window
+ * @returns {Gtk.Widget}
*/
- fillPreferencesWindow(_window) {
+ getPreferencesWidget() {
throw new GObject.NotImplementedError();
}
+
+ /**
+ * Fill the preferences window with preferences.
+ *
+ * The default implementation adds the widget
+ * returned by getPreferencesWidget().
+ *
+ * @param {Adw.PreferencesWindow} window - the preferences window
+ */
+ fillPreferencesWindow(window) {
+ const widget = this.getPreferencesWidget();
+ const page = this._wrapWidget(widget);
+ window.add(page);
+ }
+
+ _wrapWidget(widget) {
+ if (widget instanceof Adw.PreferencesPage)
+ return widget;
+
+ const page = new Adw.PreferencesPage();
+ if (widget instanceof Adw.PreferencesGroup) {
+ page.add(widget);
+ return page;
+ }
+
+ const group = new Adw.PreferencesGroup();
+ group.add(widget);
+ page.add(group);
+
+ return page;
+ }
}
export const {